void CopyTo( T[] array, int arrayIndex )

robot_2Generated
code_blocksInput

Description

The CopyTo method is used to copy the elements of the NetList<T> to a specified array, starting at a particular index of the target array. This method is useful when you need to transfer the contents of a networked list to a standard array for further processing or manipulation.

Usage

To use the CopyTo method, you need to provide a destination array and the starting index in the destination array where the copying of elements should begin. Ensure that the destination array has sufficient space to accommodate the elements being copied from the NetList<T>.

Parameters:

  • array (T[]): The destination array where elements from the NetList<T> will be copied.
  • arrayIndex (int): The zero-based index in the destination array at which copying begins.

Exceptions:

  • ArgumentNullException: Thrown if the array is null.
  • ArgumentOutOfRangeException: Thrown if arrayIndex is less than 0.
  • ArgumentException: Thrown if the number of elements in the source NetList<T> is greater than the available space from arrayIndex to the end of the destination array.

Example

public class ExampleComponent : Component
{
    [Sync] public NetList<int> MyNetList { get; set; } = new();

    public void CopyListToArray()
    {
        int[] destinationArray = new int[MyNetList.Count];
        MyNetList.CopyTo(destinationArray, 0);
        // Now destinationArray contains all elements from MyNetList
    }
}